<?php
header('Content-type:text/html;charset=utf8');
/**
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:lj
 * Date:2016-03-09
*/

/**
 * 
 * 菜单控制器
 * @author lj
 *
 */
class MenuController extends Controller{

	
	//访问控制
	function filters(){
		return array(
			'accessControl'
		);
	}
	
	
	function accessRules(){
		
		return array(  
	  /*      array('allow',  // 所有用户有操作权限：index,view  
	            'actions'=>array('index','view'),  
	            'users'=>array('*'),  
	        ),  
	        array('allow', // 仅登录用户有权限操作：create,update  
	            'actions'=>array('create','update'),  
	            'users'=>array('@'),  
	        ),  
	        array('allow', // 指定用户有权限操作：admin,delete  
	            'actions'=>array('admin','delete'),  
	            'users'=>array('admin'),  
	        ),  
	        array('deny',  // 禁止所有用户操作  
	            'users'=>array('*'),  
	        ),  */
		  array('allow', // 仅登录用户有权限操作：create,update  
	            'actions'=>array('create','update'),  
	            'users'=>array('@'),  
	        ),  
	    );  
		
	}
	
	function actionMenu(){
		$menu_model = Menu::model();
		$info = $menu_model->allParent();		
		$this->renderPartial('menuTop',array('info'=>$info));
	}
	
	function actionQuery(){
		$menu_model = Menu::model();
		$info = $menu_model->queryPages($_POST['pages_name'],$_POST['pages_parent']);		
		$this->renderPartial('menuList',array('info'=>$info));	
	}
	
	function actionToAdd(){	
		$menu_model = Menu::model();
		$info = $menu_model->allParent();
		$this->renderPartial('menuAdd',array('info'=>$info));
	}
	
	function actionUpdate($page_id){	
		$menu_model = Menu::model();
		$info = $menu_model->allParent();
		$infos = $menu_model -> getPageInfoByPageId($page_id);
		$infos = $infos[0];
		$this->renderPartial('menuUpdate',array('info'=>$info,'id'=>$page_id,'infos'=>$infos));
	}
	
	function actionAdd(){	
		$menu = new Menu();
		$menu->pages_name=$_POST['pages_name'];
		$menu->pages_parent=$_POST['pages_parent'];
		$menu->pages_address=$_POST['pages_address'];
		$menu->pages_order=$_POST['pages_order'];
		if($menu->save()){
			echo "<script>alert('添加成功');</script>";
		}else{
			echo "<script>alert('添加失败');</script>";
		}
		$menu_model = Menu::model();
		$info = $menu_model->allParent();
		$this->renderPartial('menuTop',array('info'=>$info));
	}
	/**
	 * @author xjh
	 * 修改
	 */
	function actionUpdateinfo(){
		$menu = Menu::model();
		$row = $menu -> updatePageInfoById($_POST['pages_id']);
		if($row){
			echo "<script>alert('修改成功');</script>";
			$this->redirect("./index.php?r=backweb/menu/menu");
		}else{
			echo "修改失败";
		}
	}
	
	/**
	 * @author xjh
	 * 删除(逻辑删除)
	 */
	
	function actionDel($pages_id){
		
		$menu = Menu::model();
		$row = $menu -> deletePageInfoById($pages_id);
		if($row){
			$this->redirect("./index.php?r=backweb/menu/menu");
		}else{
			echo "<script>alert('删除失败');</script>";
		}
	}
	
	
	
	
}
?>